package com.yg.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yg.pojo.TUser;
import com.yg.mapper.TUserMapper;
import com.yg.service.TUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author kotori
 * @since 2022-11-18
 */
@Service
public class TUserServiceImpl extends ServiceImpl<TUserMapper, TUser> implements TUserService {

    @Autowired
    private TUserMapper userMapper;

    @Override
    public Boolean login(String username, String password) {
        LambdaQueryWrapper<TUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(TUser::getUsername, username).eq(TUser::getPassword, password);
        TUser tUser = userMapper.selectOne(lambdaQueryWrapper);
        return tUser != null;
    }

    @Override
    public Integer getUserId(String username) {
        LambdaQueryWrapper<TUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(TUser::getUsername, username);
        return userMapper.selectOne(lambdaQueryWrapper).getId();
    }
}
